package cn.stylefeng.guns.modular.mallInformationConfig.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.ConfigInformation;
import cn.stylefeng.guns.modular.mallInformationConfig.service.IConfigInformationService;

import java.util.Date;

/**
 * 资讯信息配置控制器
 *
 * @author fengshuonan
 * @Date 2020-06-02 21:08:44
 */
@Controller
@RequestMapping("/configInformation")
public class ConfigInformationController extends BaseController {

    private String PREFIX = "/mallInformationConfig/configInformation/";

    @Autowired
    private IConfigInformationService configInformationService;

    /**
     * 跳转到资讯信息配置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "configInformation.html";
    }

    /**
     * 跳转到添加资讯信息配置
     */
    @RequestMapping("/configInformation_add")
    public String configInformationAdd() {
        return PREFIX + "configInformation_add.html";
    }

    /**
     * 跳转到修改资讯信息配置
     */
    @RequestMapping("/configInformation_update/{configInformationId}")
    public String configInformationUpdate(@PathVariable Integer configInformationId, Model model) {
        ConfigInformation configInformation = configInformationService.selectById(configInformationId);
        model.addAttribute("item",configInformation);
        LogObjectHolder.me().set(configInformation);
        return PREFIX + "configInformation_edit.html";
    }

    /**
     * 获取资讯信息配置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return configInformationService.selectList(null);
    }

    /**
     * 新增资讯信息配置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConfigInformation configInformation) {
        configInformation.setId(0);
        configInformation.setAdddate(new Date());
        configInformationService.insert(configInformation);
        return SUCCESS_TIP;
    }

    /**
     * 删除资讯信息配置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer configInformationId) {
        configInformationService.deleteById(configInformationId);
        return SUCCESS_TIP;
    }

    /**
     * 修改资讯信息配置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConfigInformation configInformation) {
        configInformation.setAdddate(new Date());
        configInformationService.updateById(configInformation);
        return SUCCESS_TIP;
    }

    /**
     * 资讯信息配置详情
     */
    @RequestMapping(value = "/detail/{configInformationId}")
    @ResponseBody
    public Object detail(@PathVariable("configInformationId") Integer configInformationId) {
        return configInformationService.selectById(configInformationId);
    }
}
